package alpha2;

import java.io.File;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Static extends Common{
	
	public static void analyze(String image) throws Exception{
		System.out.println("POST /analyze 人脸属性分析");
		
		CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost request = new HttpPost(HOST + "/analyze");
        
        MultipartEntity reqEntity = new MultipartEntity();  
        reqEntity.addPart("image", new FileBody(new File(image)));
        request.setEntity(reqEntity); 

        //发起网络请求 获取返回信息
        CloseableHttpResponse response = httpclient.execute(request);
        String responseBody = EntityUtils.toString(response.getEntity());
        
        System.out.println(responseBody);
		
	}
	
	public static void compare(String image1 , String image2) throws Exception{
		System.out.println("POST /compare 人脸比对");
		
		CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost request = new HttpPost(HOST + "/compare");
        
        MultipartEntity reqEntity = new MultipartEntity();  
        reqEntity.addPart("image_1", new FileBody(new File(image1)));
        reqEntity.addPart("image_2", new FileBody(new File(image2)));
        request.setEntity(reqEntity); 

        //发起网络请求 获取返回信息
        CloseableHttpResponse response = httpclient.execute(request);
        String responseBody = EntityUtils.toString(response.getEntity());
        
        System.out.println(responseBody);
		
	}
	
	public static void recognize(String groupId, String image, String quality, Integer limit) throws Exception{
		System.out.println("POST /recognize 静态识别");
		
		CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost request = new HttpPost(HOST + "/recognize");
        
        MultipartEntity reqEntity = new MultipartEntity();  
        reqEntity.addPart("group_id", new StringBody(groupId));
        reqEntity.addPart("image", new FileBody(new File(image)));
        reqEntity.addPart("check_quality", new StringBody(quality));
        reqEntity.addPart("limit", new StringBody(limit.toString()));
        request.setEntity(reqEntity); 

        //发起网络请求 获取返回信息
        CloseableHttpResponse response = httpclient.execute(request);
        String responseBody = EntityUtils.toString(response.getEntity());
        
        System.out.println(responseBody);
		
	}
	
	public static void verify(String groupId, String userId, String image, String quality) throws Exception{
		System.out.println("POST /verify 静态单人比对");
		
		CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost request = new HttpPost(HOST + "/verify");
        
        MultipartEntity reqEntity = new MultipartEntity();  
        reqEntity.addPart("group_id", new StringBody(groupId));
        reqEntity.addPart("user_id", new StringBody(userId));
        reqEntity.addPart("image", new FileBody(new File(image)));
        reqEntity.addPart("check_quality", new StringBody(quality));
        request.setEntity(reqEntity); 

        //发起网络请求 获取返回信息
        CloseableHttpResponse response = httpclient.execute(request);
        String responseBody = EntityUtils.toString(response.getEntity());
        
        System.out.println(responseBody);
		
	}

}
